package com.yunsc.shop.controller.order;

import com.yunsc.common.base.BaseContext;
import com.yunsc.common.utils.Result;
import com.yunsc.common.utils.SecurityUtil;
import com.yunsc.order.dto.OrderPayDTO;
import com.yunsc.order.sevice.OrderPaymentService;
import com.yunsc.order.vo.OrderInfoVO;
import com.yunsc.shop.utils.ClientInfoUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description: 订单结算
 * @date: 2024-05-20 18:33
 */
@Api(tags = "订单-结算")
@RestController
@RequestMapping("/cashier")
public class OrderCashierController {

    @Resource
    private OrderPaymentService orderPaymentService;
    @Resource
    private ClientInfoUtils clientInfoUtils;

    // /cashier/orderPay
    @ApiOperation(value = "/cashier/orderPay", tags = "订单支付")
    @PostMapping("/orderPay")
    public Result<?> orderPay(@RequestBody OrderPayDTO params) {
        Integer userId = SecurityUtil.getCurrentUserIdEx();
        Integer currentStoreId = clientInfoUtils.getCurrentStoreId();
        orderPaymentService.orderPay(params, userId,currentStoreId);
        Map<String, Object> data = new HashMap<>();
        data.put("payment", Collections.EMPTY_LIST);
        return Result.ok("订单付款成功", data);
    }

    // /cashier/orderInfo
    @ApiOperation(value = "/cashier/orderInfo", tags = "订单信息")
    @GetMapping("/orderInfo")
    public Result<?> orderInfo( OrderPayDTO params) {
        Integer userId = SecurityUtil.getCurrentUserIdEx();
        Integer currentStoreId = clientInfoUtils.getCurrentStoreId();
        OrderInfoVO orderInfo = orderPaymentService.queryOrderInfo(params.getOrderId(), params.getClient(),userId, currentStoreId);
        return Result.ok(orderInfo);
        // return Result.error("当前订单支付已超时，请重新下单");
    }


}
